#include <stdio.h>
#include <string.h>
#include <assert.h>
//void* memmove(void* destination, const void* source, size_t num);
//用法与memcpy相同，但可以拷贝重叠空间的数据

void* my_memmove(void* dest, const void* src, size_t num)
{
    assert(dest && src);
    void* ret = dest;
    //dest在前，从前向后拷
    //dest在后，从后向前拷
    if(dest < src)
    {
        while(num--)
        {
            *(char*)dest = *(char*)src;
            dest = (char*)dest + 1;
            src = (char*)src + 1;
        }
    }
    else
    {
        while(num--)
        {
            *((char*)dest + num) = *((char*)src + num);
        }
    }
    return ret;
}

int main()
{
    int arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    memmove(arr1+2, arr1, 20);

    int i = 0;
    for(i = 0; i < 10; i++)
    {
        printf("%d ", arr1[i]);
    }
    return 0;
}